package com.ktgj.customer.service.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import com.alibaba.druid.sql.visitor.functions.If;
import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.Temperature;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ktgj.common.core.annotation.Excel;
import com.ktgj.common.core.constant.FlightOrderConstants;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.utils.helper.StringHelper;
import com.ktgj.common.core.web.page.PageUtils;
import com.ktgj.customer.domain.*;
import com.ktgj.customer.domain.dto.GuaranteeCaseDTO;
import com.ktgj.customer.domain.vo.*;
import com.ktgj.customer.mapper.*;
import com.ktgj.customer.service.ICustomerService;
import com.ktgj.customer.service.IEmployeeService;
import com.ktgj.customer.service.ILoginService;
import com.ktgj.flight.api.RemoteFlightService;
import com.ktgj.flight.api.domain.AirportApi;
import com.ktgj.flight.api.domain.FlightOrderInfoApi;
import com.ktgj.flight.api.domain.FlightOrderInfoTickets;
import com.ktgj.flight.api.domain.FlightOrderInfoTicketsApi;
import com.ktgj.system.api.RemoteUserService;
import com.ktgj.system.api.domain.SysPost;
import com.sun.xml.internal.ws.api.model.MEP;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.collections4.Put;
import org.apache.ibatis.annotations.Param;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.customer.service.IGuaranteeCaseService;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

/**
 * 工单Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-15
 */
@Service
public class GuaranteeCaseServiceImpl implements IGuaranteeCaseService 
{
    @Autowired
    private GuaranteeCaseMapper guaranteeCaseMapper;
    @Autowired
    private CaseTypeMapper caseTypeMapper;
    @Autowired
    private EmployeeMapper employeeMapper;
    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private PositionMapper positionMapper;
    @Autowired
    private ILoginService loginService;
    @Autowired
    private CaseSubTypeMapper caseSubTypeMapper;
    @Autowired
    private CardMapper cardMapper;
    @Autowired
    private CustomerCardMapper customerCardMapper;
    @Autowired
    private CaseMalfeasanceMapper caseMalfeasanceMapper;
    @Autowired
    private CaseMalfeasanceLiableMapper caseMalfeasanceLiableMapper;
    @Autowired
    private CaseMalfeasanceReimbMapper caseMalfeasanceReimbMapper;
    @Autowired
    private CaseClaimMapper caseClaimMapper;
    @Autowired
    private CaseClaimPhotoMapper caseClaimPhotoMapper;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private RemoteFlightService remoteFlightService;
    @Autowired
    private CaseComplaintReimbMapper caseComplaintReimbMapper;
    @Autowired
    private CaseComplaintLiableMapper caseComplaintLiableMapper;
    @Autowired
    private CaseComplaintMapper caseComplaintMapper;
    @Autowired
    private IEmployeeService employeeService;
    @Autowired
    private CaseReimbTypeMapper caseReimbTypeMapper;
    @Autowired
    private CaseComplaintMeansMapper caseComplaintMeansMapper;
    @Autowired
    private CaseComplaintReasonMapper caseComplaintReasonMapper;
    @Autowired
    private CaseComplaintTypeMapper caseComplaintTypeMapper;
    @Autowired
    private ClaimDelayinsuranceMapper claimDelayinsuranceMapper;
    @Autowired
    private ClaimDelayinsuranceImageMapper claimDelayinsuranceImageMapper;
    @Autowired
    private RemoteUserService remoteUserService;

    /**
     * 查询工单
     * 
     * @param caseId 工单ID
     * @return 工单
     */
    @Override
    public GuaranteeCase selectGuaranteeCaseById(Long caseId)
    {
        return guaranteeCaseMapper.selectGuaranteeCaseById(caseId);
    }

    /**
     * 查询工单列表
     * 
     * @param guaranteeCase 工单
     * @return 工单
     */
    @Override
    public List<GuaranteeCase> selectGuaranteeCaseList(GuaranteeCase guaranteeCase)
    {
        return guaranteeCaseMapper.selectGuaranteeCaseList(guaranteeCase);
    }

    /**
     * 新增工单
     * 
     * @param guaranteeCase 工单
     * @return 结果
     */
    @Override
    public int insertGuaranteeCase(GuaranteeCase guaranteeCase)
    {
        return guaranteeCaseMapper.insertGuaranteeCase(guaranteeCase);
    }

    /**
     * 修改工单
     * 
     * @param guaranteeCase 工单
     * @return 结果
     */
    @Override
    public int updateGuaranteeCase(GuaranteeCase guaranteeCase)
    {
        return guaranteeCaseMapper.updateGuaranteeCase(guaranteeCase);
    }

    /**
     * 批量删除工单
     * 
     * @param caseIds 需要删除的工单ID
     * @return 结果
     */
    @Override
    public int deleteGuaranteeCaseByIds(Long[] caseIds)
    {
        return guaranteeCaseMapper.deleteGuaranteeCaseByIds(caseIds);
    }

    /**
     * 删除工单信息
     * 
     * @param caseId 工单ID
     * @return 结果
     */
    @Override
    public int deleteGuaranteeCaseById(Long caseId)
    {
        return guaranteeCaseMapper.deleteGuaranteeCaseById(caseId);
    }

    //查询工单
    @Override
    public List<GuaranteeCaseDTO> selectGuaranteeCase(GuaranteeCaseVO guaranteeCase) {
        List<GuaranteeCaseDTO> caseDTOList = new ArrayList<>();
        List<GuaranteeCase> caseList = guaranteeCaseMapper.selectGuaranteeCase(guaranteeCase.getCaseId(), guaranteeCase.getCaseStatus(), guaranteeCase.getAfterTime(),
                guaranteeCase.getAgoTime(), guaranteeCase.getOrderId(), guaranteeCase.getOrderType());
        for (GuaranteeCase aCase : caseList) {
            GuaranteeCaseDTO caseDTO = new GuaranteeCaseDTO();
            caseDTO.setCaseId(aCase.getCaseId());
            CaseType caseType = caseTypeMapper.selectCaseTypeById(aCase.getCaseTypeId());
            caseDTO.setCaseType(caseType.getCaseTypeName());
            caseDTO.setCaseSubject(aCase.getCaseSubject());
            caseDTO.setCaseContent(aCase.getCaseContent());
            Employee employee = employeeMapper.selectEmployeeById(aCase.getCreateEmployeeId());
            caseDTO.setCreateEmployee(employee.getEmployeeName());
            Department department = departmentMapper.selectDepartmentById(aCase.getDeptId());
            caseDTO.setDept(department.getDeptName());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            caseDTO.setCaseCreateTime(dateFormat.format(aCase.getCaseCreateTime()));
            PositionDTO positionDTO = positionMapper.selectPositionById(aCase.getPositionId());
            Department departmentById = departmentMapper.selectDepartmentById(positionDTO.getDeptId());
            caseDTO.setReceiveDept(departmentById.getDeptName());
            caseDTO.setReceivePosition(positionDTO.getPositionName());
            Employee employeeById = employeeMapper.selectEmployeeById(aCase.getLockEmployeeId());
            caseDTO.setLockEmployee(employeeById.getEmployeeName());
            caseDTO.setOrderId(Long.valueOf(aCase.getOrderId()));
            if (aCase.getPri() == 0) {
                caseDTO.setPri("普通");
            } else if (aCase.getPri() == 1) {
                caseDTO.setPri("紧急");
            }
            if (aCase.getCaseStatus() == 0) {
                caseDTO.setCaseStatus("待处理");
            } else if (aCase.getCaseStatus() == 1) {
                caseDTO.setCaseStatus("处理完");
            } else if (aCase.getCaseStatus() == 2) {
                caseDTO.setCaseStatus("废弃");
            }
            caseDTOList.add(caseDTO);
        }
        return caseDTOList;
    }

    //创建工单
    @Override
    public boolean addGuaranteeCase(HttpServletRequest request, GuaranteeCaseAddVO guaranteeCaseAdd) {
        Employee employee = loginService.getLoginEmployee(request);
        GuaranteeCase guaranteeCase = new GuaranteeCase();
        guaranteeCase.setCardTypeId(guaranteeCaseAdd.getCardTypeId());
        guaranteeCase.setCustomerName(guaranteeCaseAdd.getCustomerName());
        guaranteeCase.setCustomerMobile(guaranteeCaseAdd.getCustomerMobile());
        guaranteeCase.setCaseSubject(guaranteeCaseAdd.getCaseSubject());
        guaranteeCase.setCaseTypeId(guaranteeCaseAdd.getCaseTypeId());
        guaranteeCase.setCaseSubTypeId(guaranteeCaseAdd.getCaseSubTypeId());
        guaranteeCase.setCaseContent(guaranteeCaseAdd.getCaseContent());
        guaranteeCase.setPositionId(guaranteeCaseAdd.getPositionId());
        guaranteeCase.setLockEmployeeId(guaranteeCaseAdd.getLockEmployeeId());
        guaranteeCase.setPri(guaranteeCaseAdd.getPri());
        guaranteeCase.setOrderType(guaranteeCaseAdd.getOrderType());
        guaranteeCase.setOrderId(String.valueOf(guaranteeCaseAdd.getOrderId()));
        guaranteeCase.setCaseRequireFinishTime(guaranteeCaseAdd.getCaseRequireFinishTime());
        guaranteeCase.setCaseCreateTime(new Date());
        guaranteeCase.setDeptId(employee.getDeptId());
        guaranteeCase.setCreateEmployeeId(employee.getEmployeeId());
        guaranteeCase.setCaseStatus(0L);
        guaranteeCase.setCustomerId(guaranteeCaseAdd.getCustomerId());
        return guaranteeCaseMapper.insertGuaranteeCase(guaranteeCase) > 0;
    }

    /**
     * 后端——查询工单
     * */
    @Override
    public List<TemporaryGuaranteeCase> backSelectGuaranteeCase(Long customerId) throws Exception {
        if (customerId != null && customerId != 0){
            List<GuaranteeCase> guaranteeCases = guaranteeCaseMapper.backSelectGuaranteeCase(customerId);
            if (guaranteeCases != null && guaranteeCases.size() > 0){
                List<TemporaryGuaranteeCase> temporaryGuaranteeCaseList = new ArrayList<>();
                for (GuaranteeCase guaranteeCase : guaranteeCases) {
                    TemporaryGuaranteeCase temporaryGuaranteeCase = new TemporaryGuaranteeCase();
                    temporaryGuaranteeCase.setCaseId(guaranteeCase.getCaseId());
                    temporaryGuaranteeCase.setCaseType(guaranteeCase.getOrderType());
                    temporaryGuaranteeCase.setCaseSubject(guaranteeCase.getCaseSubject());
                    temporaryGuaranteeCase.setCaseContent(guaranteeCase.getCaseContent());
                    Employee employee = employeeMapper.backSelectEmployee(guaranteeCase.getCreateEmployeeId());
                    if (employee != null){
                        temporaryGuaranteeCase.setCreateEmployeeId(employee.getOthername());
                    }
                    else {
                        throw new Exception("未查到数据");
                    }
                    temporaryGuaranteeCase.setDept(guaranteeCase.getDeptId().toString());
                    temporaryGuaranteeCase.setCaseCreateTime(guaranteeCase.getCaseCreateTime());
                    temporaryGuaranteeCase.setOrderId(Long.valueOf(guaranteeCase.getOrderId()));
                    if (guaranteeCase.getPri() == 0){
                        temporaryGuaranteeCase.setPri("普通");
                    }
                    else if (guaranteeCase.getPri() == 1){
                        temporaryGuaranteeCase.setPri("紧急");
                    }
                    temporaryGuaranteeCase.setCaseStatus(guaranteeCase.getCaseStatus());
                    temporaryGuaranteeCase.setReceivingDepartment(guaranteeCase.getReceivingDepartment());
                    temporaryGuaranteeCase.setReceivePost(guaranteeCase.getReceivePost());
                    temporaryGuaranteeCase.setReceiver(guaranteeCase.getReceiver());
                    temporaryGuaranteeCaseList.add(temporaryGuaranteeCase);
                }
                return temporaryGuaranteeCaseList;
            }
            else {
                throw new Exception("未查到数据");
            }
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }

    /**
     * 后端——条件查询工单
     * */
    @Override
    public List<GuaranteeCase> backSelectGuaranteeCaseById(GuaranteeCaseVO guaranteeCase) {
//        PageUtils.startPage();
        if (guaranteeCase.getAgoTime() != null && !guaranteeCase.getAgoTime().equals(""))
            guaranteeCase.setAgoTime(guaranteeCase.getAgoTime() + " 23:59:59");
        List<GuaranteeCase> guaranteeCases = guaranteeCaseMapper.backSelectGuaranteeCaseById(guaranteeCase);

        List<GuaranteeCase> guaranteeCaseList = new ArrayList<>();
        //投诉
        if (guaranteeCase.getType() != null && guaranteeCase.getType().equals(EmHelper.workOrderType.Complaint.getValue())){
            for (GuaranteeCase aCase : guaranteeCases) {
                CaseComplaint caseComplaint = caseComplaintMapper.selectCaseComplaintById(aCase.getCaseComplaintId());
                if (caseComplaint != null){
                    aCase.setCaseType(EmHelper.workOrderType.Complaint.getValue());
                    guaranteeCaseList.add(aCase);
                }
            }
        }
        //渎失职
        else if (guaranteeCase.getType() != null && guaranteeCase.getType().equals(EmHelper.workOrderType.DerelictionDuty.getValue())){
            for (GuaranteeCase aCase : guaranteeCases) {
                CaseMalfeasance caseMalfeasance = caseMalfeasanceMapper.selectCaseMalfeasanceById(aCase.getCaseMalfeasanceId());
                if (caseMalfeasance != null){
                    aCase.setCaseType(EmHelper.workOrderType.DerelictionDuty.getValue());
                    guaranteeCaseList.add(aCase);
                }
            }
        }
        //理赔
        else if (guaranteeCase.getType() != null && guaranteeCase.getType().equals(EmHelper.workOrderType.Claim.getValue())){
            for (GuaranteeCase aCase : guaranteeCases) {
                CaseClaim caseClaim = caseClaimMapper.selectCaseClaimById(aCase.getCaseClaimId());
                if (caseClaim != null){
                    aCase.setCaseType(EmHelper.workOrderType.Claim.getValue());
                    guaranteeCaseList.add(aCase);
                }
            }
        }
        else {
            guaranteeCaseList = guaranteeCases;
        }

        if (guaranteeCaseList != null && guaranteeCaseList.size() > 0){
            for (GuaranteeCase aCase : guaranteeCaseList) {
                Employee employee = employeeMapper.backSelectEmployee(aCase.getCreateEmployeeId());
                if (employee != null){
                    aCase.setOthername(employee.getEmployeeName());
                }

                if (aCase.getReceiver()!=null && aCase.getReceiver()!="") {
                    Employee selectEmployee = employeeMapper.backSelectEmployee(Long.valueOf(aCase.getReceiver()));
                    if (selectEmployee != null) {
                        aCase.setReceiver(selectEmployee.getEmployeeName());
                    }
                }

                CaseType caseType = caseTypeMapper.selectCaseTypeById(aCase.getCaseTypeId());
                if (caseType != null){
                    aCase.setCaseTypeName(caseType.getCaseTypeName());
                }
                if (!StringHelper.isNullOrEmpty(aCase.getReceivingDepartment())) {
                    Department selectDepartment = departmentMapper.selectDepartment(Long.valueOf(aCase.getReceivingDepartment()));
                    if (selectDepartment != null) {
                        aCase.setReceivingDepartment(selectDepartment.getDeptName());
                    }
                }

                if (!StringHelper.isNullOrEmpty(aCase.getReceivePost())) {
                    PositionDTO positionDTO = positionMapper.selectPositionById(Long.valueOf(aCase.getReceivePost()));
                    if (positionDTO != null) {
                        aCase.setReceivePost(positionDTO.getPositionName());
                    }
                }

                if (aCase.getDeptId() != null && aCase.getDeptId() != 0){
                    Department department = departmentMapper.selectDepartment(aCase.getDeptId());
                    aCase.setDeptName(department.getDeptName());
                }
            }
        }

        for (GuaranteeCase caseInfo : guaranteeCaseList){
            Employee employee = employeeMapper.selectEmployeeById(caseInfo.getCreateEmployeeId());
            if (employee != null){
                caseInfo.setCreateEmployeeName(employee.getEmployeeName());
            }

            caseInfo.setJsPerson(caseInfo.getReceiver());
        }

//        List<Long> lstTmpEmployeeId = guaranteeCaseList.stream().map(item->item.getCreateEmployeeId()).collect(Collectors.toList());
//        List<Long> lstRecevierId = guaranteeCaseList.stream().map(item-> Long.valueOf(item.getReceiver())).collect(Collectors.toList());
//        lstTmpEmployeeId.addAll(lstRecevierId);
//        List<Employee> lstEmployee = employeeMapper.selectEmployeeByIds(lstTmpEmployeeId);
//        Map<Long,String> mEmployeeInfo = new HashMap<>();
//        for (Employee employee: lstEmployee)
//        {
//            mEmployeeInfo.put(employee.getEmployeeId(), employee.getEmployeeName());
//        }
//        for (GuaranteeCase caseInfo : guaranteeCaseList)
//        {
//            if (caseInfo.getCreateEmployeeId() != null)
//            {
//                caseInfo.setCreateEmployeeName(mEmployeeInfo.get(caseInfo.getCreateEmployeeId()));
//            }
//            if (!StringHelper.isNullOrEmpty(caseInfo.getReceiver()))
//            {
//                caseInfo.setJsPerson(mEmployeeInfo.get(Long.valueOf(caseInfo.getReceiver())));
//            }
//        }
        return guaranteeCaseList;
    }

    /**
     * 后端——创建工单
     * */
    @Transactional
    @Override
    public int backInsertGuaranteeCase(HttpServletRequest request, GuaranteeCaseParameter guaranteeCaseParameter) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();

        Employee loginEmployee = loginService.getLoginEmployee(request);
        if (loginEmployee == null){
            throw new Exception("登陆已过期");
        }

        CustomerIdVo tmpCustomerIdVos = new CustomerIdVo();
        tmpCustomerIdVos.setCustomerName(guaranteeCaseParameter.getCustomerName());
        tmpCustomerIdVos.setCustomerPhone(guaranteeCaseParameter.getCustomerPhone());
        if (tmpCustomerIdVos.getCustomerName() != null && !tmpCustomerIdVos.getCustomerName().equals("") &&
                tmpCustomerIdVos.getCustomerPhone() != null && !tmpCustomerIdVos.getCustomerPhone().equals("")){
            tmpCustomerIdVos = customerService.customerId(tmpCustomerIdVos);
            if (tmpCustomerIdVos == null){
                throw new Exception("会员信息有误");
            }
        }
        else {
            throw new Exception("会员姓名与会员手机号不能同时为空");
        }

        GuaranteeCase guaranteeCase = new GuaranteeCase();
        guaranteeCase.setCustomerId(tmpCustomerIdVos.getCustomerId());
        guaranteeCase.setCreateEmployeeId(guaranteeCaseParameter.getCreateEmployeeId());
        guaranteeCase.setDeptId(guaranteeCaseParameter.getDepartId());
        guaranteeCase.setCustomerCardId(guaranteeCaseParameter.getCardNum());
        guaranteeCase.setCustomerName(guaranteeCaseParameter.getCustomerName());
        guaranteeCase.setCustomerMobile(guaranteeCaseParameter.getCustomerPhone());
        guaranteeCase.setCaseTypeId(guaranteeCaseParameter.getCaseTypeId());
        guaranteeCase.setSolveContent(guaranteeCaseParameter.getSolveContent());
        if (guaranteeCaseParameter.getOrderId() != null){
            guaranteeCase.setOrderId(String.valueOf(guaranteeCaseParameter.getOrderId()));
        }

        guaranteeCase.setCaseSubject(guaranteeCaseParameter.getCaseSubject());
        guaranteeCase.setClaimCount(guaranteeCaseParameter.getClaimsSettled());
        if (guaranteeCaseParameter.getCaseType() != null){
            CaseType caseType = caseTypeMapper.backSelectCaseType(guaranteeCaseParameter.getCaseType());
            if (caseType != null){
                guaranteeCase.setCaseTypeId(caseType.getCaseTypeId());
            }
        }

        if (guaranteeCaseParameter.getCaseSubType() != null){
            CaseSubType caseSubType = caseSubTypeMapper.backSelectCaseSubTypeById(Long.valueOf(guaranteeCaseParameter.getCaseSubType()));
            if (caseSubType != null){
                guaranteeCase.setCaseSubTypeId(caseSubType.getCaseSubTypeId());
            }
        }

        if (guaranteeCaseParameter.getCardType() != null && guaranteeCaseParameter.getCardType().equals("保险理赔")){
            guaranteeCase.setCaseResponseDesc(guaranteeCaseParameter.getClaimsSettled().toString());
        }
        guaranteeCase.setCaseContent(guaranteeCaseParameter.getCaseContent());
        guaranteeCase.setCaseCreateTime(format.parse(format.format(new Date())));

        if (guaranteeCaseParameter.getPri() != null){
            guaranteeCase.setPri(Long.valueOf(guaranteeCaseParameter.getPri()));
        }

        guaranteeCase.setOrderType(guaranteeCaseParameter.getOrderType());
        if (guaranteeCaseParameter.getSpecifiedTime() != null && !guaranteeCaseParameter.getSpecifiedTime().equals("")){
            guaranteeCase.setCaseRequireFinishTime(format.parse(guaranteeCaseParameter.getSpecifiedTime()));
        }

        guaranteeCase.setCaseStatus(0l);
        guaranteeCase.setLockEmployeeId(loginEmployee.getEmployeeId());
        guaranteeCase.setReceivingDepartment(guaranteeCaseParameter.getReceivingDepartment());
        guaranteeCase.setReceivePost(guaranteeCaseParameter.getReceivePost());
        guaranteeCase.setReceiver(guaranteeCaseParameter.getReceiver());
        guaranteeCase.setCardTypeId(Long.valueOf(guaranteeCaseParameter.getCardType()));
        Long workOrderId = System.currentTimeMillis() / 1000;
        if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.DerelictionDuty.getValue())){
            guaranteeCase.setCaseMalfeasanceId(workOrderId);
        }
        else if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.Claim.getValue())){
            guaranteeCase.setCaseClaimId(workOrderId);
        }

        int i = guaranteeCaseMapper.backInsertGuaranteeCase(guaranteeCase);
        if (i > 0){
            //普通工单
            if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.Ordinary.getValue())){
                return i;
            }
            //渎失职工单
            else if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.DerelictionDuty.getValue())){
                CaseMalfeasance caseMalfeasance = new CaseMalfeasance();
                caseMalfeasance.setCaseMalfeasanceId(workOrderId);
                caseMalfeasance.setMalfeasancetype(guaranteeCaseParameter.getDerelictionDutyVo().getComplaintClassification());
                caseMalfeasance.setBusinessType(guaranteeCaseParameter.getDerelictionDutyVo().getBusinessType());
                caseMalfeasance.setOrderId(guaranteeCaseParameter.getDerelictionDutyVo().getInvolvingOrderNum());
                caseMalfeasance.setMalfeasanceContent(guaranteeCaseParameter.getDerelictionDutyVo().getVerifySituation());
                caseMalfeasance.setMalfeasanceMoney(new BigDecimal(guaranteeCaseParameter.getDerelictionDutyVo().getEmployeeAmount()));
                caseMalfeasance.setIsvalid(guaranteeCaseParameter.getDerelictionDutyVo().getNatureComplaint());
                caseMalfeasance.setComplaintEmployeeid(guaranteeCaseParameter.getDerelictionDutyVo().getComplaintEmployeeid());
                caseMalfeasance.setCount(guaranteeCaseParameter.getDerelictionDutyVo().getCount());
                caseMalfeasance.setDepartment(guaranteeCaseParameter.getDerelictionDutyVo().getDepartment());
                caseMalfeasance.setDepartmentConfirm(guaranteeCaseParameter.getDerelictionDutyVo().getDepartmentConfirm());
                caseMalfeasance.setComplaintPoint(guaranteeCaseParameter.getDerelictionDutyVo().getComplaintPoint());
                caseMalfeasance.setCancel(guaranteeCaseParameter.getDerelictionDutyVo().getCancel());
                caseMalfeasance.setFileUrl(guaranteeCaseParameter.getDerelictionDutyVo().getFileUrl());
                caseMalfeasance.setCreateDate(format.parse(format.format(date)));
                caseMalfeasance.setEmployeeId(loginEmployee.getEmployeeId());
                caseMalfeasance.setCompanyMoney(new BigDecimal(guaranteeCaseParameter.getDerelictionDutyVo().getCompanyUndertakes()));
                caseMalfeasance.setSuperior(guaranteeCaseParameter.getDerelictionDutyVo().getSuperior());
                caseMalfeasance.setTakeoffEmployee(guaranteeCaseParameter.getDerelictionDutyVo().getTakeoffEmployee());
                caseMalfeasance.setTakeoffSuperior(guaranteeCaseParameter.getDerelictionDutyVo().getTakeoffSuperior());
                caseMalfeasance.setResolutionDetails(guaranteeCaseParameter.getDerelictionDutyVo().getProcessResult());

                if (guaranteeCaseParameter.getDerelictionDutyVo().getComplaintOutcomeVo().getCompensationVoList().size() > 0){
                    for (CompensationVo compensationVo : guaranteeCaseParameter.getDerelictionDutyVo().getComplaintOutcomeVo().getCompensationVoList()) {
                        if (compensationVo.getServiceCompensation().equals(EmHelper.workOrderType.CashCompensation.getValue())){
                            caseMalfeasance.setCash(new BigDecimal(compensationVo.getCompensationAmount()));
                        }
                        else if (compensationVo.getServiceCompensation().equals(EmHelper.workOrderType.CheckOut.getValue())){
                            caseMalfeasance.setBackcardMoney(new BigDecimal(compensationVo.getCompensationAmount()));
                        }

                        if (caseMalfeasance.getMalfeasanceResult() != null){
                            caseMalfeasance.setMalfeasanceResult(caseMalfeasance.getMalfeasanceResult() + "," + compensationVo.getServiceCompensation());
                        }
                        else {
                            caseMalfeasance.setMalfeasanceResult(compensationVo.getServiceCompensation());
                        }
                    }
                }
                int insertCaseMalfeasance = caseMalfeasanceMapper.insertCaseMalfeasance(caseMalfeasance);
                if (insertCaseMalfeasance > 0){
                    if (guaranteeCaseParameter.getDerelictionDutyVo().getResponsibleVoList().size() > 0){
                        for (ResponsibleVo responsibleVo : guaranteeCaseParameter.getDerelictionDutyVo().getResponsibleVoList()) {
                            CaseMalfeasanceLiable caseMalfeasanceLiable = new CaseMalfeasanceLiable();
                            if (responsibleVo.getResponsibleDepartment()!=null)
                            {
                                caseMalfeasanceLiable.setDeptId(Long.valueOf(responsibleVo.getResponsibleDepartment()));
                            }
                            caseMalfeasanceLiable.setPunishAmount(new BigDecimal(responsibleVo.getDeductAmount()));
                            caseMalfeasanceLiable.setPunishAmountLiable(new BigDecimal(responsibleVo.getSuperiorAmount()));
                            caseMalfeasanceLiable.setCreateDate(format.parse(format.format(date)));

                            if (loginEmployee != null){
                                caseMalfeasanceLiable.setEmployeeId(loginEmployee.getEmployeeId());
                            }
                            caseMalfeasanceLiable.setIsrevoke(responsibleVo.getRevoke());
                            caseMalfeasanceLiable.setLiablePersonName(responsibleVo.getRespondent());
                            caseMalfeasanceLiable.setCaseMalfeasanceId(workOrderId);
                            int insertCaseMalfeasanceLiable = caseMalfeasanceLiableMapper.insertCaseMalfeasanceLiable(caseMalfeasanceLiable);
                            if (insertCaseMalfeasanceLiable <= 0){
                                throw new Exception(responsibleVo.getRespondent() + "的渎失职责任创建异常");
                            }
                        }
                    }

                    if (guaranteeCaseParameter.getDerelictionDutyVo().getComplaintOutcomeVo().getCompensationVoList().size() > 0){
                        for (CompensationVo compensationVo : guaranteeCaseParameter.getDerelictionDutyVo().getComplaintOutcomeVo().getCompensationVoList()) {
                            CaseMalfeasanceReimb caseMalfeasanceReimb = new CaseMalfeasanceReimb();
                            caseMalfeasanceReimb.setReimbTypeId(compensationVo.getServiceCompensation());
                            caseMalfeasanceReimb.setReimbAmount(new BigDecimal(compensationVo.getCompensationAmount()));

                            if (loginEmployee != null){
                                caseMalfeasanceReimb.setEmployeeId(loginEmployee.getEmployeeId());
                            }

                            caseMalfeasanceReimb.setCaseMalfeasanceId(workOrderId);
                            int insertCaseMalfeasanceReimb = caseMalfeasanceReimbMapper.insertCaseMalfeasanceReimb(caseMalfeasanceReimb);
                            if (insertCaseMalfeasanceReimb <= 0){
                                throw new Exception(compensationVo.getServiceCompensation() + "的渎失职赔偿创建异常");
                            }
                        }
                    }

                    if (guaranteeCaseParameter.getDerelictionDutyVo().getDocumentVoList() != null && guaranteeCaseParameter.getDerelictionDutyVo().getDocumentVoList().size() > 0){
                        for (DocumentVo documentVo : guaranteeCaseParameter.getDerelictionDutyVo().getDocumentVoList()) {
                            CaseClaimPhoto caseClaimPhoto = new CaseClaimPhoto();
                            caseClaimPhoto.setClaimPhotoPath(documentVo.getUrl());
                            caseClaimPhoto.setClaimPhotoType(documentVo.getType());
                            caseClaimPhoto.setCaseClaimId(workOrderId);
                            int photo = caseClaimPhotoMapper.insertCaseClaimPhoto(caseClaimPhoto);
                            if (photo <= 0){
                                throw new Exception("添加图片/文件失败" + documentVo.getUrl());
                            }
                        }
                    }

                    guaranteeCase.setCaseMalfeasanceId(caseMalfeasance.getCaseMalfeasanceId());
                    guaranteeCaseMapper.updateGuaranteeCase(guaranteeCase);
                    return 1;
                }
                else {
                    throw new Exception("渎失职工单创建异常");
                }
            }
            //理赔工单
            else if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.Claim.getValue())){
                CustomerIdVo customerIdVo = new CustomerIdVo();
                if (guaranteeCaseParameter.getCardNum() != null && !guaranteeCaseParameter.getCardNum().equals("")){
                    customerIdVo.setCustomerCard(guaranteeCaseParameter.getCardNum());
                }
                if (guaranteeCaseParameter.getCustomerName() != null && !guaranteeCaseParameter.getCustomerName().equals("")){
                    customerIdVo.setCustomerName(guaranteeCaseParameter.getCustomerName());
                }
                if (guaranteeCaseParameter.getCustomerPhone() != null && !guaranteeCaseParameter.getCustomerPhone().equals("")){
                    customerIdVo.setCustomerPhone(guaranteeCaseParameter.getCustomerPhone());
                }
                if (customerIdVo != null){
                    customerIdVo = customerService.customerId(customerIdVo);
                }
                else {
                    throw new Exception("没有会员信息");
                }

//                ClaimDelayinsurance claimDelayinsurance = new ClaimDelayinsurance();
//                claimDelayinsurance.setCustomerId(customerIdVo.getCustomerId().toString());
//                claimDelayinsurance.setFlightstatus(0l);
//                claimDelayinsurance.setDelayclaimorderid(guaranteeCaseParameter.getOrderId());
//                try {
//                    claimDelayinsurance.setArriveDate(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime()));
//                } catch (Exception e){
//                    claimDelayinsurance.setArriveDate(dateFormat.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime()));
//                }
//
//                claimDelayinsurance.setRealFlyawayDate(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualDepartureTime()));
//                claimDelayinsurance.setRealArriveDate(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualLandingTime()));
//                claimDelayinsurance.setIsvalid(0l);
//                claimDelayinsurance.setInvoiceId(guaranteeCase.getCaseId());
//                try {
//                    claimDelayinsurance.setDepartureTime(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime()));
//                } catch (Exception e){
//                    claimDelayinsurance.setDepartureTime(dateFormat.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime()));
//                }
//
//                claimDelayinsurance.setDeparture(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneySetOff());
//                claimDelayinsurance.setArrival(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneyArrive());
//                claimDelayinsurance.setFlightno(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightNumber());
//                claimDelayinsurance.setLatedate(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayDate()));
//                claimDelayinsurance.setState(0l);
//                claimDelayinsurance.setClaimtime(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayTime()));
//                claimDelayinsurance.setCreateTime(date);
//                claimDelayinsurance.setOrderId(guaranteeCaseParameter.getOrderId());
//                claimDelayinsurance.setRemark(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getReplenish());
//                int delayinsurance = claimDelayinsuranceMapper.insertClaimDelayinsurance(claimDelayinsurance);
//                if (delayinsurance <= 0){
//                    throw new Exception("保险理赔信息添加失败");
//                }

//                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList() != null && guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList().size() > 0) {
//                    for (DocumentVo documentVo : guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList()) {
//                        ClaimDelayinsuranceImage claimDelayinsuranceImage = new ClaimDelayinsuranceImage();
//                        claimDelayinsuranceImage.setImageUrl(documentVo.getUrl());
//                        claimDelayinsuranceImage.setId(claimDelayinsurance.getDelayinsuranceId());
//                        claimDelayinsuranceImage.setImageType(documentVo.getType());
//                        int image = claimDelayinsuranceImageMapper.insertClaimDelayinsuranceImage(claimDelayinsuranceImage);
//                        if (image <= 0){
//                            throw new Exception("保险理赔图片添加失败" + documentVo.getUrl());
//                        }
//                    }
//                }

                CaseClaim caseClaim = new CaseClaim();
                caseClaim.setCaseClaimId(workOrderId);
                caseClaim.setExpectFinishTime(format.parse(guaranteeCaseParameter.getClaimVo().getFinish()));
                caseClaim.setExpectReplyTime(Long.parseLong(guaranteeCaseParameter.getClaimVo().getReply()));
                caseClaim.setCustomerId(customerIdVo.getCustomerId());
                caseClaim.setCustomername(customerIdVo.getCustomerName());
                caseClaim.setFavoree(customerIdVo.getCustomerName());
                caseClaim.setClaimCount(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getClaimCount());
                caseClaim.setDelayContent(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayContent());
                caseClaim.setPhone(customerIdVo.getCustomerPhone());
                caseClaim.setFlightno(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightNumber());
                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayDate() != null){
                    caseClaim.setLatedate(dateFormat.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayDate()));
                }

                caseClaim.setCreateId(loginEmployee.getEmployeeId());
                caseClaim.setIsvalid(EmHelper.workOrderType.PendingReview.getValue());
                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime() != null){
                    try {
                        caseClaim.setDepartureTime(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime()));
                    } catch (Exception e){
                        caseClaim.setDepartureTime(dateFormat.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime()));
                    }
                }

                caseClaim.setDelaytime(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDelayTime());

                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneySetOff() != null &&
                        !guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneySetOff().equals("")){
                    Map<String, Object> map = new HashMap<>();
                    map.put("airportCityName", guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneySetOff());
                    List<AirportApi> airportApis = remoteFlightService.selectAirportLike(map);
                    caseClaim.setDeparture(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneySetOff());
                    if (airportApis != null && airportApis.size() > 0)
                        caseClaim.setDeparturecode(airportApis.get(0).getAirportCityId());
                }

                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneyArrive() != null &&
                        !guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneyArrive().equals("")){
                    Map<String, Object> map = new HashMap<>();
                    map.put("airportCityName", guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneyArrive());
                    List<AirportApi> airportApis = remoteFlightService.selectAirportLike(map);
                    caseClaim.setArrival(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getJourneyArrive());
                    if (airportApis != null && airportApis.size() > 0)
                        caseClaim.setArrivalcode(airportApis.get(0).getAirportCityId());
                }

                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualDepartureTime() != null){
                    caseClaim.setRealFlyawayDate(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualDepartureTime()));
                }

                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualLandingTime() != null){
                    caseClaim.setReallandingtime(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getActualLandingTime()));
                }

                if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime() != null){
                    try {
                        caseClaim.setScheduledlandingtime(format.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime()));
                    } catch (Exception e){
                        caseClaim.setScheduledlandingtime(dateFormat.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime()));
                    }
                }

                caseClaim.setFlightstatus(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightStatus());
                if (guaranteeCaseParameter.getOrderId() != null){
                    caseClaim.setFligthorderid(guaranteeCaseParameter.getOrderId());
                }

                caseClaim.setFlightstatus(guaranteeCaseParameter.getFlightStatus());
                int insertCaseClaim = caseClaimMapper.insertCaseClaim(caseClaim);
                if (insertCaseClaim > 0){
                    int count = 0;
                    if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList() != null &&
                            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList().size() > 0){
                        for (DocumentVo documentVo : guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDocumentVoList()) {
                            CaseClaimPhoto caseClaimPhoto = new CaseClaimPhoto();
                            caseClaimPhoto.setClaimPhotoPath(documentVo.getUrl());
                            caseClaimPhoto.setClaimPhotoType(documentVo.getType());
                            caseClaimPhoto.setCaseClaimId(workOrderId);
                            int claimPhoto = caseClaimPhotoMapper.insertCaseClaimPhoto(caseClaimPhoto);
                            count = count + 1;
                            if (claimPhoto <= 0){
                                throw new Exception("第" + count + "次创建理赔图片失败");
                            }
                        }
                    }
                }
                else {
                    throw new Exception("理赔工单创建失败");
                }

                guaranteeCase.setCaseClaimId(caseClaim.getCaseClaimId());
                guaranteeCaseMapper.updateGuaranteeCase(guaranteeCase);
                return 1;
            }
            //投诉工单
            else if (guaranteeCaseParameter.getWorkOrderType().equals(EmHelper.workOrderType.Complaint.getValue())){
                CustomerIdVo customerIdVo = new CustomerIdVo();
                customerIdVo.setCustomerName(guaranteeCaseParameter.getCustomerName());
                customerIdVo.setCustomerCard(guaranteeCaseParameter.getCardNum());
                customerIdVo.setCustomerPhone(guaranteeCaseParameter.getCustomerPhone());
                CustomerIdVo tmpCustomerIdVo = customerService.customerId(customerIdVo);

                CaseComplaint caseComplaint = new CaseComplaint();
                if (guaranteeCase != null){
                    caseComplaint.setCaseId(guaranteeCase.getCaseId());
                }

                caseComplaint.setCustomerId(tmpCustomerIdVo.getCustomerId());

                Employee employee = new Employee();
                List<Employee> employees = employeeService.selectEmployeeList(employee);
                if (employees != null && employees.size() == 1){
                    caseComplaint.setComplaintEmployeeid(employees.get(0).getEmployeeId());
                }
                caseComplaint.setComplaintDate(format.parse(format.format(date)));
                if (guaranteeCaseParameter.getComplaintVo()!=null)
                {
                    employee.setEmployeeName(guaranteeCaseParameter.getComplaintVo().getCustomerComplaintVo().getRespondent());
                    caseComplaint.setComplaintMeansId(guaranteeCaseParameter.getComplaintVo().getCustomerComplaintVo().getComplainWay());
                    caseComplaint.setComplaintReasonId(guaranteeCaseParameter.getComplaintVo().getCustomerComplaintVo().getComplaintReason());
                    caseComplaint.setComplaintEmployeename(guaranteeCaseParameter.getComplaintVo().getCustomerComplaintVo().getRespondent());
                    caseComplaint.setConfirmationDetails(guaranteeCaseParameter.getComplaintVo().getCustomerPhone());
                    caseComplaint.setReimbursementAmt(new BigDecimal(guaranteeCaseParameter.getComplaintVo().getCompensationAmount()));
                    caseComplaint.setComplaintTypeId(guaranteeCaseParameter.getComplaintVo().getCustomerComplaintVo().getComplaintClassification());
                    CaseComplaintLiable caseComplaintLiable = new CaseComplaintLiable();
                    caseComplaintLiable.setDeptId(Long.valueOf(guaranteeCaseParameter.getReceivingDepartment()));

                    Employee employe = new Employee();
                    employee.setEmployeeName(guaranteeCaseParameter.getReceiver());
                    List<Employee> employes = employeeService.selectEmployeeList(employe);
                    if (employes != null && employes.size() == 1){
                        caseComplaintLiable.setEmployeeId(employes.get(0).getEmployeeId());
                    }
                    caseComplaintLiable.setCaseComplaintId(workOrderId);
                    caseComplaintLiable.setPunishAmount(Long.valueOf(guaranteeCaseParameter.getComplaintVo().getCompensationAmount()));

                    if (guaranteeCaseParameter.getComplaintVo().getCompensationVoList() != null &&
                            guaranteeCaseParameter.getComplaintVo().getCompensationVoList().size() > 0){
                        for (CompensationVo compensationVo : guaranteeCaseParameter.getComplaintVo().getCompensationVoList()) {
                            CaseComplaintReimb caseComplaintReimb = new CaseComplaintReimb();
                            caseComplaintReimb.setReimbTypeId(Long.valueOf(compensationVo.getServiceCompensation()));
                            caseComplaintReimb.setReimbAmount(new BigDecimal(compensationVo.getCompensationAmount()));
                            caseComplaintReimb.setCaseComplaintId(workOrderId);
                            int reimb = caseComplaintReimbMapper.insertCaseComplaintReimb(caseComplaintReimb);
                            if (reimb <= 0){
                                throw new Exception("添加投诉赔偿结果失败" + compensationVo.getServiceCompensation());
                            }
                        }
                    }
                    int liable = caseComplaintLiableMapper.insertCaseComplaintLiable(caseComplaintLiable);
                    if (liable <= 0){
                        throw new Exception("添加投诉解决责任人失败");
                    }
                }
                int complaint = caseComplaintMapper.insertCaseComplaint(caseComplaint);
                if (complaint <= 0){
                    throw new Exception("创建投诉工单失败");
                }
                guaranteeCase.setCaseComplaintId(caseComplaint.getCaseComplaintId());
                guaranteeCaseMapper.updateGuaranteeCase(guaranteeCase);
                return 1;
            }
            else {
                throw new Exception("无法识别的工单类型");
            }
        }
        else {
            throw new Exception("工单创建异常");
        }
    }

    /**
     * app--创建工单
     * */
    @Override
    public int insertGuaranteeCase(HttpServletRequest request, GuaranteeCaseParameter guaranteeCaseParameter) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Customer customer = loginService.getLoginCustomer(request);
        CustomerIdVo customerIdVo = new CustomerIdVo();
        customerIdVo.setCustomerId(customer.getCustomerId());
        CustomerIdVo tmpCustomerIdVo = customerService.customerId(customerIdVo);
        guaranteeCaseParameter.setCardType(tmpCustomerIdVo.getCustomerCardType());
        guaranteeCaseParameter.setCaseSubject("理赔");
        guaranteeCaseParameter.setCaseType("理赔");
        guaranteeCaseParameter.setCaseSubType("理赔");
        guaranteeCaseParameter.setClaimsSettled(0l);
        guaranteeCaseParameter.setReceivePost("系统管理员");
        guaranteeCaseParameter.setReceiver("系统管理员");
        guaranteeCaseParameter.setPri("0");
        guaranteeCaseParameter.setOrderType(EmHelper.businessType.FLIGHT.getValue());
        guaranteeCaseParameter.setCardNum(tmpCustomerIdVo.getCustomerCard());
        guaranteeCaseParameter.setCustomerName(tmpCustomerIdVo.getCustomerName());
        guaranteeCaseParameter.setCustomerPhone(tmpCustomerIdVo.getCustomerPhone());
        guaranteeCaseParameter.setWorkOrderType(EmHelper.workOrderType.Claim.getValue());

        ClaimVo claimVo = new ClaimVo();
        claimVo.setTemplate("理赔");
        claimVo.setWorkOrderContentVo(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo());
        guaranteeCaseParameter.setClaimVo(claimVo);

        List<FlightOrderInfoTicketsApi> flightOrderInfoTicketsApi;
        if (guaranteeCaseParameter.getOrderId() != null &&guaranteeCaseParameter.getOrderId() != 0){
            Map<String, Object> map = new HashMap<>();
            map.put("orderId", guaranteeCaseParameter.getOrderId());
            flightOrderInfoTicketsApi = remoteFlightService.selFlightOrderInfoById(map);
        }
        else {
            FlightOrderInfoTickets flightOrderInfoTickets = new FlightOrderInfoTickets();
            flightOrderInfoTickets.setFlight(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightNumber());
            if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime() != null){
                try {
                    flightOrderInfoTickets.setDepartureTime(date.parse(guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime()));
                } catch (Exception e){
                    throw new Exception("日期转换错误");
                }
            }
            flightOrderInfoTickets.setOrgAirport(guaranteeCaseParameter.getOrgAirportCord());
            flightOrderInfoTickets.setDstAirport(guaranteeCaseParameter.getDstAirportCord());
            flightOrderInfoTicketsApi = remoteFlightService.selFlightOrderInfo(flightOrderInfoTickets);
        }

        if (flightOrderInfoTicketsApi == null || flightOrderInfoTicketsApi.size() <= 0){
            throw new Exception("订单号不存在");
        }

        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightNumber() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getFlightNumber().equals("")){
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setFlightNumber(flightOrderInfoTicketsApi.get(0).getFlight());
        }
        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalSetOffTime() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalSetOffTime().equals("")){
            String departureTime = format.format(flightOrderInfoTicketsApi.get(0).getDepartureTime());
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setOriginalSetOffTime(departureTime);
        }
        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalLandingTime().equals("")){
            String departureTime = format.format(flightOrderInfoTicketsApi.get(0).getArrivalTime());
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setOriginalLandingTime(departureTime);
        }
        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getOriginalDepartureTime().equals("")){
            String departureTime = format.format(flightOrderInfoTicketsApi.get(0).getDepartureTime());
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setOriginalDepartureTime(departureTime);
        }
        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDepartureAirport() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDepartureAirport().equals("")){
            Map<String, Object> departureAirport = new HashMap<>();
            departureAirport.put("airportId", guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getDepartureAirport());
            AirportApi airportApi = remoteFlightService.getAirportInfoByAirportName(departureAirport);
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setDepartureAirport(airportApi.getAirportName());
        }
        if (guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getArriveAirport() == null ||
                guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getArriveAirport().equals("")){
            Map<String, Object> arriveAirport = new HashMap<>();
            arriveAirport.put("airportId", guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().getArriveAirport());
            AirportApi airportApi = remoteFlightService.getAirportInfoByAirportName(arriveAirport);
            guaranteeCaseParameter.getClaimVo().getWorkOrderContentVo().setArriveAirport(airportApi.getAirportName());
        }

        guaranteeCaseParameter.setWorkOrderType(EmHelper.workOrderType.Claim.getValue());
        int aCase = backInsertGuaranteeCase(request, guaranteeCaseParameter);
        return aCase;
    }

    /**
     * 后端——查询工单详细
     * */
    @Override
    public GuaranteeCaseParameterVo backGuaranteeCaseById(Long caseId) throws Exception {
        if (caseId != null && caseId != 0){
            GuaranteeCase guaranteeCase = guaranteeCaseMapper.backGuaranteeCaseById(caseId);
            if (guaranteeCase != null){
                GuaranteeCaseParameterVo guaranteeCaseParameterVo = new GuaranteeCaseParameterVo();
                if (!StringHelper.isNullOrEmpty(guaranteeCase.getReceiver())){
                    Employee employee = employeeMapper.backSelectEmployee(Long.valueOf(guaranteeCase.getReceiver()));
                    if (employee != null){
                        guaranteeCaseParameterVo.setReceiver(employee.getEmployeeName());
                        guaranteeCaseParameterVo.setReceiverId(employee.getEmployeeId());
//                        guaranteeCase.setReceiver(employee.getEmployeeName());
                    }
                }

                if (!StringHelper.isNullOrEmpty(guaranteeCase.getReceivePost())){
                    PositionDTO positionDTO = positionMapper.selectPositionById(Long.valueOf(guaranteeCase.getReceivePost()));
                    if (positionDTO!=null)
                    {
                        guaranteeCaseParameterVo.setReceivePost(positionDTO.getPositionName());
                        guaranteeCaseParameterVo.setReceivePostId(positionDTO.getPositionId());
//                        guaranteeCase.setReceivePost(positionDTO.getPositionName());
                    }
                }
                if (!StringHelper.isNullOrEmpty(guaranteeCase.getReceivingDepartment()))
                {
                    Department department = departmentMapper.selectDepartmentById(Long.valueOf(guaranteeCase.getReceivingDepartment()));
                    if (department!=null)
                    {
                        guaranteeCaseParameterVo.setReceiveDepartment(department.getDeptName());
                        guaranteeCaseParameterVo.setReceiveDepartmentId(department.getDeptId());
//                        guaranteeCase.setReceivingDepartment(department.getDeptId().toString());
//                        guaranteeCase.setReceivingDepartmentName(department.getDeptName());
                    }
                }
                CustomerCard customerCard = customerCardMapper.backSelectCustomerCardByCardCode(guaranteeCase.getCustomerCardId());
                if (customerCard != null){
                    Card card = cardMapper.selectCardByCardId(customerCard.getCardId());

                    if (card != null){
                        guaranteeCaseParameterVo.setCardNumberId(card.getCardId());
                        guaranteeCaseParameterVo.setCardNumberType(card.getCardSectionName());
                    }
                    else {
                        throw new Exception("未查到会员卡类型");
                    }
                }

                if (guaranteeCase.getPri() != null){
                    guaranteeCaseParameterVo.setEmergencyLevel(guaranteeCase.getPri().toString());
                }
                guaranteeCaseParameterVo.setMemberCardNumber(guaranteeCase.getCustomerCardId());
                guaranteeCaseParameterVo.setMemberName(guaranteeCase.getCustomerName());
                guaranteeCaseParameterVo.setMemberCellPhone(guaranteeCase.getCustomerMobile());
                guaranteeCaseParameterVo.setWorkOrderSubclass(guaranteeCase.getCaseSubTypeId()==null?"":guaranteeCase.getCaseSubTypeId().toString());
                if (guaranteeCase.getCaseClaimId()!=null)
                {
                    guaranteeCaseParameterVo.setTicketType("claim");
                }
                if (guaranteeCase.getCaseMalfeasanceId()!=null)
                {
                    guaranteeCaseParameterVo.setTicketType("derelictionDuty");
                }
                if (guaranteeCase.getCaseComplaintId()!=null)
                {
                    guaranteeCaseParameterVo.setTicketType("complaint");
                }
                if (guaranteeCase.getCaseClaimId()==null && guaranteeCase.getCaseMalfeasanceId()==null && guaranteeCase.getCaseClaimId()==null)
                {
                    guaranteeCaseParameterVo.setTicketType("ordinary");
                }
                guaranteeCaseParameterVo.setCardNumberId(guaranteeCase.getCardTypeId());
                guaranteeCaseParameterVo.setTicketTitle(guaranteeCase.getCaseSubject());
                guaranteeCaseParameterVo.setWorkOrderContent(guaranteeCase.getCaseContent());
                guaranteeCaseParameterVo.setOrderType(guaranteeCase.getOrderType());
                guaranteeCaseParameterVo.setRelevantOrderNumber(guaranteeCase.getOrderId());
                guaranteeCaseParameterVo.setCaseTypeId(guaranteeCase.getCaseTypeId());
                guaranteeCaseParameterVo.setSolveContent(guaranteeCase.getSolveContent());
//                guaranteeCaseParameterVo.setReceiver(guaranteeCase.getReceiver());
//                guaranteeCaseParameterVo.setReceivePost(guaranteeCase.getReceivePost());
//                guaranteeCaseParameterVo.setReceiveDepartment(guaranteeCase.getReceivingDepartment());
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if (guaranteeCase.getCaseRequireFinishTime() != null){
                    guaranteeCaseParameterVo.setSpecifiedTime(format.format(guaranteeCase.getCaseRequireFinishTime()));
                }

                if (guaranteeCase.getCreateEmployeeId() != null){
                    guaranteeCaseParameterVo.setFounder(guaranteeCase.getCreateEmployeeId().toString());
                }
                if (guaranteeCase.getDeptId() != null){
                    guaranteeCaseParameterVo.setCreateCepartment(guaranteeCase.getDeptId().toString());
                }
                guaranteeCaseParameterVo.setWorkOrderStatus(guaranteeCase.getCaseStatus().toString());
                return guaranteeCaseParameterVo;
            }
            else {
                throw new Exception("未查到数据");
            }
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }

    @Override
    public List<TmpGuaranteeCaseVo> selectworkOrderType(Long deptId) {
        List<TmpGuaranteeCaseVo> tmpGuaranteeCaseVoList = new ArrayList<>();
        List<CaseSubType> caseSubTypes = caseSubTypeMapper.caseSubTypeList(deptId);
        if (caseSubTypes.size() > 0){
            for (CaseSubType caseSubType : caseSubTypes) {
                TmpGuaranteeCaseVo tmpGuaranteeCaseVo = new TmpGuaranteeCaseVo();
                tmpGuaranteeCaseVo.setCaseSubTypeId(caseSubType.getCaseSubTypeId());
                tmpGuaranteeCaseVo.setWorkOrderType(caseSubType.getCaseSubType());
                tmpGuaranteeCaseVoList.add(tmpGuaranteeCaseVo);
            }
        }
        return tmpGuaranteeCaseVoList;
    }

    /**
     * 查询待修改的工单信息
     * */
    @Override
    public GuaranteeCaseParameter guaranteeCaseParameter(Long caseId) {
        GuaranteeCaseParameter guaranteeCaseParameter = new GuaranteeCaseParameter();
        GuaranteeCase guaranteeCase = guaranteeCaseMapper.backGuaranteeCaseById(caseId);
        CaseComplaint caseComplaints = caseComplaintMapper.selectCaseComplaintByCaseId(caseId);

        Card card = cardMapper.cardLevel(guaranteeCase.getCardTypeId());
        if (card != null){
            guaranteeCaseParameter.setCardType(card.getCardSectionName());
        }

        guaranteeCaseParameter.setCaseSubject(guaranteeCase.getCaseSubject());

        CaseType caseType = caseTypeMapper.backSelectCaseTypeById(guaranteeCase.getCardTypeId());
        if (caseType != null){
            guaranteeCaseParameter.setCaseType(caseType.getCaseTypeName());
        }

        CaseSubType caseSubType = caseSubTypeMapper.backSelectCaseSubTypeById(guaranteeCase.getCaseSubTypeId());
        if (caseSubType != null){
            guaranteeCaseParameter.setCaseSubType(caseSubType.getCaseSubType());
        }

        guaranteeCaseParameter.setClaimsSettled(guaranteeCase.getClaimCount());
        guaranteeCaseParameter.setCaseContent(guaranteeCase.getCaseContent());
        guaranteeCaseParameter.setReceivingDepartment(guaranteeCase.getReceivingDepartment());
        guaranteeCaseParameter.setReceivePost(guaranteeCase.getReceivePost());
        guaranteeCaseParameter.setReceiver(guaranteeCase.getReceiver());

        if (guaranteeCase.getPri() != null && guaranteeCase.getPri() == 0){
            guaranteeCaseParameter.setPri("普通");
        }
        else if (guaranteeCase.getPri() != null && guaranteeCase.getPri() == 1){
            guaranteeCaseParameter.setPri("紧急");
        }

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (guaranteeCase.getCaseRequireFinishTime() != null){
            guaranteeCaseParameter.setSpecifiedTime(format.format(guaranteeCase.getCaseRequireFinishTime()));
        }

        guaranteeCaseParameter.setOrderId(Long.valueOf(guaranteeCase.getOrderId()));
        guaranteeCaseParameter.setCardNum(guaranteeCase.getCustomerCardId());
        guaranteeCaseParameter.setCustomerName(guaranteeCase.getCustomerName());
        guaranteeCaseParameter.setCustomerPhone(guaranteeCase.getCustomerMobile());

        //渎失职工单
        if (guaranteeCase.getCaseMalfeasanceId() != null && guaranteeCase.getCaseMalfeasanceId() != 0){
            guaranteeCaseParameter.setWorkOrderType("渎失职");

            CaseMalfeasance caseMalfeasance = caseMalfeasanceMapper.selectCaseMalfeasanceById(guaranteeCase.getCaseMalfeasanceId());
            if (caseMalfeasance  != null){
                DerelictionDutyVo derelictionDutyVo = new DerelictionDutyVo();
                if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.HOTEL.getValue())){
                    derelictionDutyVo.setBusinessType("酒店");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.FLIGHT.getValue())){
                    derelictionDutyVo.setBusinessType("机票");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.SERVICE.getValue())){
                    derelictionDutyVo.setBusinessType("贵宾厅");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.TRAIN.getValue())){
                    derelictionDutyVo.setBusinessType("火车票");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.VIPAisle.getValue())){
                    derelictionDutyVo.setBusinessType("vip通道");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.CheckIn.getValue())){
                    derelictionDutyVo.setBusinessType("值机");
                }
                else if (caseMalfeasance.getBusinessType().equals(EmHelper.businessType.Customer.getValue())){
                    derelictionDutyVo.setBusinessType("会员");
                }

                derelictionDutyVo.setInvolvingOrderNum(caseMalfeasance.getOrderId());
                derelictionDutyVo.setEmployeeAmount(caseMalfeasance.getMalfeasanceMoney().toString());
                derelictionDutyVo.setCompanyUndertakes(caseMalfeasance.getCompanyMoney().toString());
                derelictionDutyVo.setProcessResult(caseMalfeasance.getResolutionDetails());

                List<DocumentVo> documentVoList = new ArrayList<>();
                List<CaseClaimPhoto> caseClaimPhotos = caseClaimPhotoMapper.selectCaseClaimPhotoListByCaseClaimId(caseMalfeasance.getCaseMalfeasanceId());
                if (caseClaimPhotos != null && caseClaimPhotos.size() > 0){
                    for (CaseClaimPhoto caseClaimPhoto : caseClaimPhotos) {
                        DocumentVo documentVo = new DocumentVo();
                        documentVo.setType(caseClaimPhoto.getClaimPhotoType());
                        documentVo.setUrl(caseClaimPhoto.getClaimPhotoPath());
                        documentVoList.add(documentVo);
                    }
                }
                derelictionDutyVo.setDocumentVoList(documentVoList);

                List<ResponsibleVo> responsibleVoList = new ArrayList<>();
                List<CaseMalfeasanceLiable> caseMalfeasanceLiables = caseMalfeasanceLiableMapper.selectLiableByMalfeasanceId(caseMalfeasance.getCaseMalfeasanceId());
                if (caseMalfeasanceLiables != null && caseMalfeasanceLiables.size() > 0){
                    for (CaseMalfeasanceLiable caseMalfeasanceLiable : caseMalfeasanceLiables) {
                        ResponsibleVo responsibleVo = new ResponsibleVo();

                        Department department = departmentMapper.selectDepartmentById(caseMalfeasanceLiable.getDeptId());
                        if (department != null){
                            responsibleVo.setResponsibleDepartment(department.getDeptName());
                        }

                        Employee employeeByEmployeeId = employeeMapper.backSelectEmployee(caseMalfeasanceLiable.getEmployeeId());
                        if (employeeByEmployeeId != null){
                            responsibleVo.setRespondent(employeeByEmployeeId.getEmployeeName());
                        }

                        responsibleVo.setDeductAmount(caseMalfeasanceLiable.getPunishAmount().toString());

                        Employee employeeByLiableId = employeeMapper.backSelectEmployee(caseMalfeasanceLiable.getLiableId());
                        if (employeeByLiableId != null){
                            responsibleVo.setSuperior(employeeByLiableId.getEmployeeName());
                        }

                        responsibleVo.setSuperiorAmount(caseMalfeasanceLiable.getPunishAmountLiable().toString());
                        responsibleVo.setRevoke(caseMalfeasanceLiable.getIsrevoke());
                        responsibleVoList.add(responsibleVo);
                    }
                }
                derelictionDutyVo.setResponsibleVoList(responsibleVoList);

                ComplaintOutcomeVo complaintOutcomeVo = new ComplaintOutcomeVo();
                List<CompensationVo> compensationVoList = new ArrayList<>();
                List<CaseMalfeasanceReimb> caseMalfeasanceReimbs = caseMalfeasanceReimbMapper.selectCaseMalfeasanceReimbByCaseMalfeasanceId(caseMalfeasance.getCaseMalfeasanceId());
                if (caseMalfeasanceReimbs != null && caseMalfeasanceReimbs.size() > 0){
                    for (CaseMalfeasanceReimb caseMalfeasanceReimb : caseMalfeasanceReimbs) {
                        CompensationVo compensationVo = new CompensationVo();
                        CaseReimbType caseReimbType = caseReimbTypeMapper.selectCaseReimbTypeById(Long.valueOf(caseMalfeasanceReimb.getReimbTypeId()));
                        if (caseReimbType != null){
                            compensationVo.setServiceCompensation(caseReimbType.getReimbType());
                        }

                        compensationVo.setCompensationAmount(caseMalfeasanceReimb.getReimbAmount().toString());
                        compensationVoList.add(compensationVo);
                    }
                }
                complaintOutcomeVo.setCompensationVoList(compensationVoList);

                derelictionDutyVo.setComplaintOutcomeVo(complaintOutcomeVo);
                guaranteeCaseParameter.setDerelictionDutyVo(derelictionDutyVo);
            }
        }
        //理赔工单
        else if (guaranteeCase.getCaseClaimId() != null && guaranteeCase.getCaseClaimId() != 0){
            guaranteeCaseParameter.setWorkOrderType("理赔");
            ClaimVo claimVo = new ClaimVo();
            CaseClaim caseClaim = caseClaimMapper.selectCaseClaimById(guaranteeCase.getCaseClaimId());
            if (caseClaim != null){
                claimVo.setTemplate(guaranteeCase.getCaseContent());
                if (guaranteeCase.getCaseExpFinishTime() != null){
                    claimVo.setFinish(format.format(guaranteeCase.getCaseExpFinishTime()));
                }

                WorkOrderContentVo workOrderContentVo = new WorkOrderContentVo();
                workOrderContentVo.setDelayTime(caseClaim.getDelaytime());
                if (caseClaim.getLatedate() != null){
                    workOrderContentVo.setDelayDate(format.format(caseClaim.getLatedate()));
                }

                if (caseClaim.getDepartureTime() != null){
                    workOrderContentVo.setOriginalSetOffTime(format.format(caseClaim.getDepartureTime()));
                }

                workOrderContentVo.setFlightNumber(caseClaim.getFlightno());

                Map<String, Object> departureMap = new HashMap<>();
                departureMap.put("airportCityId", caseClaim.getDeparturecode());
                List<AirportApi> departureAirportApis = remoteFlightService.selectAirportName(departureMap);
                if (departureAirportApis != null && departureAirportApis.size() > 0){
                    workOrderContentVo.setJourneySetOff(departureAirportApis.get(0).getAirportCityName());
                }

                Map<String, Object> arrivalMap = new HashMap<>();
                arrivalMap.put("airportCityId", caseClaim.getArrivalcode());
                List<AirportApi> arrivalAirportApis = remoteFlightService.selectAirportName(arrivalMap);
                if (arrivalAirportApis != null && arrivalAirportApis.size() > 0){
                    workOrderContentVo.setJourneyArrive(arrivalAirportApis.get(0).getAirportCityName());
                }

                workOrderContentVo.setFlightStatus(caseClaim.getFlightstatus());

                if (caseClaim.getDepartureTime() != null){
                    workOrderContentVo.setOriginalDepartureTime(format.format(caseClaim.getDepartureTime()));
                }

                if (caseClaim.getRealFlyawayDate() != null){
                    workOrderContentVo.setActualDepartureTime(format.format(caseClaim.getRealFlyawayDate()));
                }

                if (caseClaim.getScheduledlandingtime() != null){
                    workOrderContentVo.setOriginalLandingTime(format.format(caseClaim.getScheduledlandingtime()));
                }

                if (caseClaim.getReallandingtime() != null){
                    workOrderContentVo.setActualLandingTime(format.format(caseClaim.getReallandingtime()));
                }

                List<DocumentVo> documentVoList = new ArrayList<>();
                List<CaseClaimPhoto> caseClaimPhotos = caseClaimPhotoMapper.selectCaseClaimPhotoListByCaseClaimId(caseClaim.getCaseClaimId());
                if (caseClaimPhotos != null && caseClaimPhotos.size() > 0){
                    for (CaseClaimPhoto caseClaimPhoto : caseClaimPhotos) {
                        DocumentVo documentVo = new DocumentVo();
                        documentVo.setType(caseClaimPhoto.getClaimPhotoType());
                        documentVo.setUrl(caseClaimPhoto.getClaimPhotoPath());
                        documentVoList.add(documentVo);
                    }
                }

                workOrderContentVo.setDocumentVoList(documentVoList);
                claimVo.setWorkOrderContentVo(workOrderContentVo);
                guaranteeCaseParameter.setClaimVo(claimVo);
            }
        }
        //投诉工单
        else if (caseComplaints != null){
            guaranteeCaseParameter.setWorkOrderType("投诉");
            CaseComplaint caseComplaint = caseComplaintMapper.selectCaseComplaintByCaseId(caseId);
            if (caseComplaint != null){
                ComplaintVo complaintVo = new ComplaintVo();
                CustomerComplaintVo customerComplaintVo = new CustomerComplaintVo();
                customerComplaintVo.setRespondent(caseComplaint.getComplaintEmployeename());

                CaseComplaintMeans caseComplaintMeans = caseComplaintMeansMapper.selectCaseComplaintMeansById(caseComplaint.getComplaintMeansId());
                if (caseComplaintMeans != null){
                    customerComplaintVo.setComplainWayName(caseComplaintMeans.getComplaintMeans());
                }

                CaseComplaintReason caseComplaintReason = caseComplaintReasonMapper.selectCaseComplaintReasonById(caseComplaint.getComplaintReasonId());
                if (caseComplaintReason != null){
                    customerComplaintVo.setComplaintReasonName(caseComplaintReason.getComplaintReason());
                }

                if (caseComplaint.getComplaintDate() != null){
                    customerComplaintVo.setComplaintDate(format.format(caseComplaint.getComplaintDate()));
                }

                CaseComplaintType caseComplaintType = caseComplaintTypeMapper.selectCaseComplaintTypeById(caseComplaint.getComplaintTypeId());
                if (caseComplaintType != null){
                    customerComplaintVo.setComplaintClassificationName(caseComplaintType.getComplaintType());
                }

                complaintVo.setCustomerComplaintVo(customerComplaintVo);
                complaintVo.setCustomerPhone(caseComplaint.getConfirmationDetails());
                if (caseComplaint.getReimbursementAmt() != null && caseComplaint.getReimbursementAmt().compareTo(new BigDecimal(0)) != 0){
                    complaintVo.setCompensationAmount(caseComplaint.getReimbursementAmt().toString());
                }

                List<CompensationVo> compensationVoList = new ArrayList<>();
                List<CaseComplaintReimb> caseComplaintReimbs = caseComplaintReimbMapper.selectCaseComplaintReimbByCaseComplaintId(caseComplaint.getCaseComplaintId());
                if (caseComplaintReimbs != null && caseComplaintReimbs.size() > 0){
                    for (CaseComplaintReimb caseComplaintReimb : caseComplaintReimbs) {
                        CompensationVo compensationVo = new CompensationVo();

                        CaseReimbType caseReimbType = caseReimbTypeMapper.selectCaseReimbTypeById(caseComplaintReimb.getReimbTypeId());
                        if (caseReimbType != null){
                            compensationVo.setServiceCompensation(caseReimbType.getReimbType());
                        }

                        if (caseComplaintReimb.getReimbAmount() != null && caseComplaintReimb.getReimbAmount().compareTo(new BigDecimal(0)) != 0){
                            compensationVo.setCompensationAmount(caseComplaintReimb.getReimbAmount().toString());
                        }
                        compensationVoList.add(compensationVo);
                    }
                    complaintVo.setCompensationVoList(compensationVoList);
                }
                guaranteeCaseParameter.setComplaintVo(complaintVo);
            }
        }
        else {
            guaranteeCaseParameter.setWorkOrderType("普通");
        }
        return guaranteeCaseParameter;
    }
}
